# @param {String} s
# @return {Integer}
def length_of_longest_substring(s)
  res, tmp = 0, []
  s.each_char do |char|
    idx = tmp.index(char)
    res, tmp[0..idx] = [res, tmp.size].max, [] if idx
    tmp << char
  end
  [res, tmp.size].max
end

s = "abcabcbb"
require 'byebug'
byebug
puts length_of_longest_substring(s).inspect
